import {
  api,
  util,
  storage
} from '../util'
import {
  router
} from '../router';
import { setStorageSync } from '../compatible';
var app = getApp();
var theme={
  loadPageWidgets(page_id,user_id,data_cache_key,callback){
    let data = storage.get(data_cache_key + page_id);
    if (data != undefined && data.length > 0) {
      callback(data);
      return;
    }
    // 获取远程post数据的参数
    let param = {
      FKFlag: app.dns.proprietor,
      FKWay: app.dns.fkWay,
      UserId: user_id, // 登录用户Id,
      Sid: app.dns.proprietorId, //网页所有者Id,
      ProprietorId: app.dns.proprietorId,
      Id: page_id
    };
    // 通过post方式获取远程数据,不显示加载图标
    util.post("theme.data.widgetsdata", param, function (res) {
      let data = res.data;
      let widgets = [];
      if (data.Success) { 
        var result = data.Content;
        if (result.length > 0) {
          //过滤掉重复的
          for (let i = 0; i < result.length; i++) {
            let item = result[i] || {};
            if (item.WidgetName != '' && item.WidgetName !='undefined' && item.WidgetHeight > 0) {
              item.Datas = [];
              widgets.push(item);
            }
          }
          storage.put(data_cache_key + page_id, widgets, page_id == 0 ? 0 : 180);
        }
      }
      callback(widgets);
    }, '3.0', null, false);
  },
  loadPageWidgetsName(user_id,callback){
    let param = {
      FKFlag: app.dns.proprietor,
      FKWay: app.dns.fkWay,
      UserId: user_id, // 登录用户Id,
      Sid: app.dns.proprietorId, //网页所有者Id,
      Proprietor:app.dns.proprietor,
      ProprietorId: app.dns.proprietorId,
      WidgetName:'FootBar'
    };
    // 通过post方式获取远程数据,不显示加载图标
    util.post("theme.data.widgetbyname", param, function (res) {
      let data = res.data;
      let copy_result = [];
      if (data.Success) { 
        var result = data.Content;
        copy_result.push(result);
        callback(copy_result);
      }
    }, '3.0', null, false);
  },
  linkTo(url){
    var links = url;
    if (url == null || url == undefined || url == "") return;
    if(url.indexOf('wxa.redirect?') > -1){
      url = url
    }else{
      url = url.toLowerCase();
    }
    let ps = url.split('?');
    let path = "";
    let param = "";
    if (ps.length > 1) {
      param = ps[1];
    }
    let pages = getCurrentPages() //获取加载的页面
    let currentPage = pages[pages.length - 1] //获取当前页面的对象
    let current_url = currentPage.route //当前页面url
    //商品列表
    if (url.indexOf('category.aspx') > -1 || url.indexOf('product/list.aspx') > -1 || url.indexOf('supplier/product/list') > -1 || url.indexOf('quick.aspx') > -1 ) {
      //品牌id
      let bid = getQueryString("bid", param);
      if(bid != null){
        app.globalData.product_list.bid = bid;
      }else{
        app.globalData.product_list.bid = 0;    //清理品牌数据
      }
      //分类id
      let cid = getQueryString("cid", param);
      app.globalData.product_list.cid =0;
      app.dns.cid = 0;
      if (cid != null) {
        app.globalData.product_list.cid = cid;
        app.dns.cid = cid;
      }
      //关键词
      let index_search_keyword = getQueryString("sm", param);
      if (index_search_keyword != null) {
        app.globalData.product_list.index_search_keyword = index_search_keyword;
      }
      //促销规则id
      let rule_id = getQueryString("promid", param);
      if (rule_id != null) {
        app.globalData.product_list.rule_id = rule_id;
      }
      //标签id
      let tag_id = getQueryString("tagid",param);
      if(tag_id!=null){
        app.globalData.product_list.tag_id = tag_id;
      }
      if(url.indexOf('category.aspx') > -1 || url.indexOf('quick.aspx') > -1){
        router.navigate({
          path: "productList",
          params:{hasnav:true,cid:app.dns.cid}
        });
      }else{
        router.navigate({
          path: "productList",
          params:{cid:app.dns.cid}
        });
      }
      
    }
    else if (url.indexOf('supplier/product/category')>-1 || url.indexOf('newcategory') > -1){
      router.switchTab({
        path: "classify"
      });
    }
    //商品
    else if (url.indexOf('product.aspx') > -1 || url.indexOf('product.aspx') > -1 || (url.indexOf('supplier/product/detail') > -1 && getQueryString("discounttype", param) == null) || (url.indexOf('supplier/product/detail') > -1 && getQueryStringPanic("discounttype=3", param) != null)) {
      param = param.replace('pid', 'id');
      path = "productDetail";
      let params = getRouterParams(param);
      params["ptype"] = params["discounttype"];
      router.navigate({
        path: path,
        params: params
      });
    }
    //拼团预售商品
    else if (url.indexOf('supplier/product/detail') > -1 && getQueryString("discounttype", param) != null) {
      param = param.replace('pid', 'productId');
      path = "groupDetail";
      var params = getRouterParams(param);
      params["ptype"] = params["discounttype"];
      params["id"] = params["discountid"];
      router.navigate({
        path: path,
        params: params
      });
    }   
   
    //入驻
    else if (url.indexOf('register.aspx') > -1 || url.indexOf('register/store') > -1) {
      path = "register";
      router.navigate({
        path: path,
        params:{
          role:"store"
        }
      });
    }
    //快速下单
    else if (url.indexOf('oftenbuylist') > -1 || url.indexOf('supplier/product/quick-order') > -1 || url.indexOf('favorite.aspx') > -1 || url.indexOf('oftenbuy.aspx') > -1 || url.indexOf('againbuy.aspx') > -1) {
      setStorageSync('tabcurrent', 0) //快速下单
      if(url.indexOf('favorite.aspx') > -1 ){//收藏
        setStorageSync('tabcurrent', 1)
      }
      if(url.indexOf('oftenbuy.aspx') > -1 ){//常购
        setStorageSync('tabcurrent', 2)
      }
      if(url.indexOf('againbuy.aspx') > -1 ){//复购
        setStorageSync('tabcurrent', 3)
      }
      path = "category";
      router.switchTab({
        path: path
      });
    }
    //拼团
    else if (url.indexOf('grouplist') > -1 || url.indexOf('supplier/fight-groups') > -1) {
      path = "groupList";
      router.navigate({
        path: path,
        params: {
          flag: "1"
        }
      });
    }
    //预售
    else if (url.indexOf('presalelist') > -1 || url.indexOf('supplier/presale') > -1) {
      path = "presellList";
      router.navigate({
        path: path,
        params: {
          flag: "2"
        }
      });
    }
    //限时特价
    else if (url.indexOf('panicbuylist') > -1 || url.indexOf('supplier/sp-price') > -1) {
      path = "panicBuyList";
      router.navigate({
        path: path
      });
    }
    //促销大全
    else if (url.indexOf('promotions') > -1 || url.indexOf('store/promotion') > -1) {
      path = "promotionlist";
      router.navigate({
        path: path
      });
    }
    //在线领取优惠优惠
    else if (url.indexOf('couponsdetails') > -1 || url.indexOf('store/coupon/detail') > -1) {
      path = "couponDetail";
      router.navigate({
        path: path,
        params: getRouterParams(param)
      });
    }
    else if (url.indexOf('coupons.aspx?') > -1 || url.indexOf('supplier/coupon') > -1) {
      router.navigate({
        path: "receivedCouponList"
      });
    }
    //消息中心
    else if (url.indexOf('infolist') > -1 || url.indexOf('common/msg') > -1) {
      router.navigate({
        path: "msgList"
      });
    }
    else if(url.indexOf('packed/list') > -1){//套餐列表
      wx.navigateTo({
        url: '/pages/store/purchase/setmealList/index',
      })
    }
    else if (url.indexOf('/game/') > -1 || url.indexOf('store/game/luckdraw') > -1) {
      path = "squaredPaper";
      router.navigate({
        path: path,
        params: getRouterParams(param)
      });
    }
    else if (url.indexOf('integral') > -1 || url.indexOf('integral.aspx')>-1 || url.indexOf('integral/integralofmine')>-1) {//积分
      path = "integral";
      router.navigate({
        path: path,
        params: getRouterParams(param)
      });
    }
    else if(url.indexOf('deposit') > -1 && url.indexOf('/finance/prestore.aspx') > -1 || url.indexOf("finance/prestore")>-1 || url.indexOf('finance/prestoreofmine')>-1 ){//预存款
      path = "recharge";
      router.navigate({
        path: path,
        params: getRouterParams(param)
      });
    }
    else if(url.indexOf('order/orderlist') > -1 || links.indexOf('store/order/list') > -1 || url.indexOf('orderlist.aspx') > -1){//订单列表
      router.navigate({
        path: "orderList"
      });
    }
    else if(url.indexOf('credit/creditofmine') > -1 || url.indexOf('creditofmine.aspx') > -1){//我的授信
      router.navigate({
        path: "billList"
      });
    }
    else if(url.indexOf('dealing.aspx') > -1 ){//对账
      router.navigate({
        path: "dealing"
      });
    }
    else if(url.indexOf('coupons/couponsofmine') > -1 || url.indexOf('couponsofmine.aspx') > -1){//我的优惠券
      router.navigate({
        path: "myCouponList"
      });
    }
    else if(url.indexOf('common/distribution') > -1){//分销
      path = "distributionApply";
      router.navigate({
        path: path,
        params: getRouterParams(param)
      });
    }
    else if (url.indexOf("main") > -1 || url.indexOf("store/buyer") > -1 || url.indexOf("storecenter") > -1){ //我的
      setStorageSync('tabindex', app.dns.centerNum);
      router.switchTab({
        path: "center"
      });
    }else if(url.indexOf("cart.aspx") > -1 || url.indexOf("cart") > -1){//购物车
      setStorageSync('tabindex', app.dns.cartNum);
      router.switchTab({
        path: "cart"
      });
    }else if(url.indexOf('common/find') > -1 || url.indexOf("discover") > -1){ //发现
      wx.navigateTo({
        url: '/packageCommunity/pages/find/index',
      })
    }
    //首页
    else if (url.indexOf('default.aspx') > -1 || url.split('/')[url.split('/').length - 1].indexOf("supplier") == 0) {
      path = "index";
      let reg = /page\s*=\s*(\d*)/;
      param=param.replace("pageid=","page=") ;
      let rs_match = param.match(reg);
      if (rs_match && rs_match.length > 1) {
        path = "customIndex";
        router.navigate({
          path: path,
          params: getRouterParams(param)
        });
      }
      else {
        if (current_url == "pages/index") return;
        router.switchTab({
          path: path
        });

      }
    }
    else if(url.indexOf('wxa.redirect') > -1){//跳转小程序
      var wxUrl = url.replace('wxa.redirect?','');
      wxUrl = wxUrl.split('&');
      var paths = '',version = '',appid = '',extra = '';
      for(var i = 0; i < wxUrl.length; i ++) {
        var pair = wxUrl[i].split("=");
        if(pair[0] == 'wxauri'||pair[0] == 'wxaUri'){
          paths = wxUrl[i].replace(pair[0]+'=','');
          if(paths.indexOf('#')>-1){
            paths = paths.replace('#','=')
          }
        }
        if(pair[0] == 'version'){
          version = pair[1];
        }
        if(pair[0] == 'appid'){
          appid = pair[1];
        }
        if(pair[0] == 'extra'){
          extra = JSON.parse(pair[1]);
        }
      }
      wx.navigateToMiniProgram({
        appId: appid,//小程序appid
        path: paths,//跳转关联小程序app.json配置里面的地址
        extraData: extra,
       //**重点**要打开的小程序版本，有效值 develop（开发版），trial（体验版），release（正式版） 
        envVersion: version,
        success(res) {
          // 打开成功
          console.log(res)
        },
        fail(err){
          console.log(err);
        }
      })
    }
    else if(url.indexOf('scan.aspx') > -1){//扫码
      wx.scanCode({
        success: (res) => {
          app.globalData.product_list.index_search_keyword = res.result;
          router.navigate({
            path: "productList"
          });
        }
      })
    }
    else if (url.indexOf(api.domain)>-1){
      let dir = (storage.get("LoginSessionVirtualDirKey") || "");
      let index = url.indexOf(dir);
      let hashPath = url.substring(index + dir.length);      
      router.navigate({
        path: "transfer",
        params: {
          // action: "skip",
          // hashPath: hashPath
          thirdDomain: encodeURIComponent(links)
        }
      });
    }else{
      wx.navigateTo({
        url: '/pages/common/medium/index?url='+encodeURIComponent(links),
      })
    }
  },
  routerTo(path,param){
    if(typeof(param)=="string"){
      router.navigate({
        path: path,
        params:getRouterParams(param)
      });
    }
    else{
      router.navigate({
        path: path,
        params: param
      });
    }
  },
  //获取底部导航装修数据
  getFootBar(widgets,callback){
    let array = [];
    let originList = []
    let footerBar = widgets.filter((item) => item.WidgetName == "FootBar");
    if(footerBar&&footerBar.length>0&&footerBar[0].Datas!=undefined&&footerBar[0].Datas.length>0){
      let footerBarData = footerBar[0].Datas.filter((item) => item.IsSelected==true);
      originList = footerBarData
      footerBarData.map((item,index)=>{
        let links='';
        let selectedIconPath = item.SelectedIconPath || ''
        let iconPath = item.IconPath || ''
        if (selectedIconPath) {
          selectedIconPath = api.imgDomain + selectedIconPath
        }
        if (iconPath) {
          iconPath = api.imgDomain + iconPath
        }
        if(links.indexOf('wxa.redirect') > -1){
          links= item.Link?item.Link:item.Keyword;
        }else{
          links= item.Link?(item.Link).toLowerCase():(item.Keyword).toLowerCase();
        }
        let ps = links.split('?');
        let param = "";
        if (ps.length > 1) {
          param = ps[1];
        }
        theme.linkList(links,2,item.Alias)
        if(links=='home' || links.indexOf('supplier/default.aspx') > -1){ //首页
          array.push({
            selectIcon:'icon-a-xingzhuang5kaobei1',
            icon:'icon-shouye',
            text:item.Alias || item.Name,
            type:1,
            pagePath:'/pages/index',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if (links.indexOf('integral') > -1 || links.indexOf('integral.aspx')>-1 || links.indexOf('integral/integralofmine')>-1) {//积分
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/finance/intergral/intergral',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('deposit') > -1 || links.indexOf("finance/prestore") >-1){//预存款
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/finance/recharge/recharge',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('order/orderlist') > -1 || links.indexOf('store/order/list') > -1 || links.indexOf('orderlist.aspx') > -1){//订单列表
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/purchase/list/list',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('credit/creditofmine') > -1 || links.indexOf('creditofmine.aspx') > -1){//我的授信
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/credit/bill_list/bill_list',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('dealing.aspx') > -1 ){//对账
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/purchase/dealing/dealing',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links=='category' || links.indexOf('quick.aspx') > -1 || links.indexOf('product/list.aspx') > -1){//商品
          //关键词
          // let ps = links.split('?');
          // let param = "";
          // if (ps.length > 1) {
          //   param = ps[1];
          // }
          //品牌id
          let bid = getQueryString("bid", param);
          if(bid != null){
            app.globalData.product_list.bid = bid;
          }else{
            app.globalData.product_list.bid = 0;    //清理品牌数据
          }
          //分类id
          let cid = getQueryString("cid", param);
          if (cid != null) {
            app.globalData.product_list.cid = cid;
          }
          //关键词
          let index_search_keyword = getQueryString("sm", param);
          if (index_search_keyword != null) {
            app.globalData.product_list.index_search_keyword = index_search_keyword;
          }
          //促销规则id
          let rule_id = getQueryString("promid", param);
          if (rule_id != null) {
            app.globalData.product_list.rule_id = rule_id;
          }
          //标签id
          let tag_id = getQueryString("tagid",param);
          if(tag_id!=null){
            app.globalData.product_list.tag_id = tag_id;
          }
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/product/list/list',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links=='newcategory' || links.indexOf('categorys.aspx') > -1){//分类
          array.push({
            selectIcon:'icon-fenlei21',
            icon:'icon-fenlei11',
            text:item.Alias || item.Name,
            type:1,
            pagePath:'/pages/store/purchase/classify/classify',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links=='fastorder' || links.indexOf('oftenbuylist.aspx') > -1 || links.indexOf('favorite.aspx') > -1 || links.indexOf('oftenbuy.aspx') > -1 || links.indexOf('againbuy.aspx') > -1 || links.indexOf('category.aspx') > -1){//快速下单
          var fastId = 0;//快速下单
          if(links.indexOf('favorite.aspx') > -1 ){//收藏
            fastId = 1;
          }
          else if(links.indexOf('oftenbuy.aspx') > -1 ){//常购
            fastId = 2;
          }
          else if(links.indexOf('againbuy.aspx') > -1 ){//复购
            fastId = 3;
          }
          else{
            let cid = getQueryString("cid", param);
            app.dns.cid = cid;
          }
          array.push({
            selectIcon:'icon-kuaisuxiadan21',
            icon:'icon-kuaisuxiadan11',
            text:item.Alias || item.Name,
            type:1,
            pagePath:'/pages/store/purchase/fast/fast',
            fastId:fastId,
            cid:app.dns.cid,
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links=='cart' || links.indexOf('/cart.aspx') > -1){//购物车
          api.CartName = item.Alias || item.Name
          array.push({
            selectIcon:'icon-a-xingzhuang11kaobei2',
            icon:'icon-jinhuoche',
            text: item.Alias || item.Name,
            type:1,
            keyword:'cart',
            pagePath:'/pages/store/purchase/cart/cart',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('product.aspx') > -1 || (links.indexOf('supplier/product/detail') > -1 && getQueryString("discounttype", param) == null) || (links.indexOf('supplier/product/detail') > -1 && getQueryStringPanic("discounttype=3", param) != null)){
          // let ps = links.split('?');
          // let param = "";
          // if (ps.length > 1) {
          //   param = ps[1];
          // }
          param = param.replace('pid', 'id');
          array.push({ 
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:3,
            url:param,
            pagePath:'/packageStore/pages/product/detail/detail',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('supplier/product/detail') > -1 && getQueryString("discounttype", param) != null){//拼团预售商品详情
          param = param.replace('pid', 'productId');
          var params = getRouterParams(param);
          params["ptype"] = params["discounttype"];
          params["id"] = params["discountid"];
          array.push({ 
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:3,
            url:param,
            pagePath:'/packageStore/pages/market/group/detail',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links=='discover' || links.indexOf('common/find') > -1){//发现
          array.push({
            selectIcon:'icon-faxian21',
            icon:'icon-faxian11',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageCommunity/pages/find/index',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links=='storecenter' || links.indexOf('webstore/main.aspx') > -1 || links.indexOf("main") > -1 || links.indexOf("store/buyer") > -1 || links.indexOf("storecenter") > -1){//我的
          array.push({
            selectIcon:'icon-wode21',
            icon:'icon-wode11',
            text:item.Alias || item.Name,
            type:1,
            pagePath:'/pages/store/profile/index',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('panicbuylist.aspx') > -1){//限时特价
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/market/panicbuy/list',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('grouplist.aspx') > -1){//拼团列表
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/market/group/list?flag=1',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('presalelist.aspx') > -1){//预售列表
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/market/group/list?flag=2',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('coupons.aspx') > -1){//领券中心
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/market/coupon/list',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('coupons/couponsofmine') > -1 || links.indexOf('couponsofmine.aspx') > -1){//我的优惠券
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/purchase/coupon/coupon',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('promotions.aspx') > -1){//促销大全
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/market/promotions/list',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('infolist.aspx') > -1){//消息中心
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/packageStore/pages/profile/msg/list',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('packed/list') > -1){//套餐列表
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/pages/store/purchase/setmealList/index',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('wxa.redirect') > -1){
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/pages/common/miniProgram/index?link='+encodeURIComponent(links),
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('register.aspx') > -1 || links.indexOf('register/store') > -1){//入驻
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/pages/account/register/register?role=store',
            index:index,
            selectedIconPath,
            iconPath
          })
        }else if(links.indexOf('default.aspx') > -1 || links.split('/')[links.split('/').length - 1].indexOf("supplier") == 0){//首页
          let reg = /page\s*=\s*(\d*)/;
          param=param.replace("pageid=","page=") ;
          let rs_match = param.match(reg);
          if (rs_match && rs_match.length > 1) {
            array.push({
              selectIcon:'icon-ft_fast_on',
              icon:'icon-ft_fast',
              text:item.Alias || item.Name,
              type:2,
              pagePath:'/pages/custom?'+param,
              index:index,
              selectedIconPath,
              iconPath
            })
          } else {
            if (current_url == "pages/index") return;
            array.push({
              selectIcon:'icon-a-xingzhuang5kaobei1',
              icon:'icon-shouye',
              text:item.Alias || item.Name,
              type:1,
              pagePath:'/pages/index',
              index:index,
              selectedIconPath,
              iconPath
            })
          }
        }else if(links.indexOf('scan.aspx') > -1){ //扫码
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:4,
            pagePath:'scan',
            index:index,
            selectedIconPath,
            iconPath
          })
        } else if (links.indexOf('/game/') > -1 || links.indexOf('store/game/luckdraw') > -1) {
          // 抽奖页面
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:3,
            url:param,
            pagePath:'/pages/game/squared-paper/index',
            index:index,
            selectedIconPath,
            iconPath
          })
        } else{
          array.push({
            selectIcon:'icon-goumai1',
            icon:'icon-goumai2',
            text:item.Alias || item.Name,
            type:2,
            pagePath:'/pages/common/medium/index?url='+encodeURIComponent(links),
            index:index,
            selectedIconPath,
            iconPath
          })
        }
      })
      storage.put('tabBar',array)
      storage.put('originTabbar', footerBarData)
    }else {
      let tablist = storage.get("tabBar");
      originList = storage.get('originTabbar') || []
      if (tablist&&tablist.length>0) {
        array = tablist;
      }else{
        array = app.globalData.defaultTabBars;
      }
    }
    app.globalData.tabBar.list = array;
    app.globalData.tabBar.originList = originList
    app.initTabBar();
  },
  linkList(url){

  },
  /**
   * 获取首页/自定义页面的配置信息
   * @param {*} page_id 页面id
   * @param {*} callback 回调处理函数
   */
  getIndexPageConfig (page_id = 0, callback) {
    // 获取远程post数据的参数
    let param = {
      FKFlag: app.dns.proprietor,
      FKId: app.dns.proprietorId,
      FKWay: app.dns.fkWay || 2,
      PageId: page_id || 0,
      SiteType: 2
    };
    // 通过post方式获取远程数据,不显示加载图标
    util.post("theme.webpage.detail", param, function (res) {
      let data = res.data || {}
      if (data.Success) {
        callback(data.Content)
      } else {
        callback({})
      }
    }, '3.0', null, false);
  },
}

function getQueryString(name,param) {
  let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  let r = param.match(reg);
  if (r != null) return unescape(r[2]); return null;
}
function getQueryStringPanic(name,param){
  let reg = new RegExp("(^|&)" + name);
  let r = param.match(reg);
  if (r != null) return unescape(r[2]); return null;
}
function getRouterParams(param) {
  let params={};
  let arr = param.split("&");
  for (var i = 0; i < arr.length; i++) {
    if (arr[i].indexOf("=")!=-1){
      params[arr[i].split("=")[0]] = arr[i].split("=")[1];
    }

  }
  return params;  
}
export{
  theme,
  getRouterParams,
  getQueryString,
  getQueryStringPanic
}